# coding:utf-8
import time

from selenium import webdriver

import setting

wd = webdriver.Chrome(setting.WEBDRIVERURI)
wd.implicitly_wait(10)

wd.get('https://www.python.org/')

# 修改标题
time.sleep(1)
JS1 = 'document.title="我是修改后的标题";'
wd.execute_script(JS1)

# 弹出现在的标题
time.sleep(1)
JS2 = r'alert($(document).attr("title"));'
wd.execute_script(JS2)
wd.switch_to.alert.accept()

# 搜索
time.sleep(1)
wd.find_element_by_id('id-search-field').send_keys('pycon')
wd.find_element_by_id('submit').click()


wd.find_element_by_css_selector(r'#content > div > section > form > ul > li:nth-child(1) > h3>a').click()
wd.save_screenshot('content.png')


# 结束浏览器
time.sleep(3)
wd.quit()
